package IO.Buffered;

import java.io.*;
import java.net.URL;

/**
 * 转换流(inputStreamReader,outputStreamWriter)
 * 1.以字符流的形式操作节点流(纯文本)
 * 2.可以指定字符集
 */
public class ConvertTest02 {
    public static void main(String[] args) {
        //操作网络流 下载百度的源代码
        try(BufferedReader reader =
                    new BufferedReader(
                            new InputStreamReader(
                                    new URL("http://www.baidu.com").openStream(),"UTF-8"));
            BufferedWriter writer =
                    new BufferedWriter(
                            new OutputStreamWriter(
                                    new FileOutputStream("src/IO/Buffered/baidu.html"),"UTF-8"));){
            //操作读取
            String msg;
            while ((msg=reader.readLine())!=null){
               //保存成html文件
               writer.write(msg);
               writer.newLine();
            }
        }catch (IOException e){
            System.out.println("操作异常");
        }
    }
}
